-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pydantic V2 support #13
Conversation
Added Pydantic V2 support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Could you add some tests and run make lint
to fix the linting issues?
@@ -169,6 +169,16 @@ def validate(cls, v: str) -> Self: | |||
raise ValueError("invalid data-uri format") | |||
return m | |||
|
|||
@classmethod | |||
def __get_pydantic_json_schema__(cls, core_schema: Any, handler: Any) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't core_schema
have type Mapping[str, Any]
, as in pydantic_core?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, added mapping Dict
== '{"content": "data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0' | ||
'aGUgbGF6eSBkb2cu"}' | ||
instance.__getattr__(func_json)() | ||
== '{"content":"data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu"}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we test both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to test for this edge case
- Updated the test suite in 'tests/test_pydantic.py' to enhance compatibility with various Pydantic versions. - Previously, the test suite attempted to access attributes 'model_dump_json' and 'model_dump' without exception handling, potentially causing test failures with specific Pydantic versions. - In this commit, we've improved compatibility by handling AttributeError exceptions and determining the appropriate functions ('json' and 'dict') to use based on the available Pydantic version.
Added Pydantic V2 support